import request from '../utils/request';
import qs from 'qs';
console.log(process.env.NODE_ENV, '环境', process.env.downloadApi, process.env.apiTest);

export async function getUserInfo(params) {
  return request(`${process.env.apiTest}/getInfo`, {
    method: 'GET',
    body: params
  });
}

/**
 *  用户名密码登录
 * @param {*} params  请求的参数
 */
export async function doLoginByUserNameAndPassword(params) {
  return request(
    `${process.env.apiTest}/login`,
    {
      method: 'POST',
      body: params
    },
    {
      showMessage: false
    }
  );
}

/**
 * 退出登录
 * @param {*} params 退出登录
 */
export async function logout(params) {
  return request(`${process.env.apiTest}/logout`, {
    method: 'POST',
    body: params
  });
}

/**
 * 获取用户菜单
 * @param {用户信息} params
 */
export async function getMenu(params) {
  return request(`${process.env.apiTest}/getAllMenuList`, {
    method: 'GET',
    body: params
  });
}
// // 获取权限设置
// export async function setPower(params) {
//   return request(`${process.env.apiTest}/AdministratorsSa`, {
//     method: 'GET',
//     body: params
//   });
// }
// // 设置权限保存接口
// export async function savePower(params) {
//   return request(`${process.env.apiTest}/AdministratorsSave`, {
//     method: 'POST',
//     body: params
//   });
// }

// /**
//  *  获取应用列表
//  * @param {*} params
//  */
// export async function getAppManagerList(params){
//     return request(`/api/org/appmanager/queryList",{
//         method:"GET",
//         body:params
//     })
// }

// 重置密码
export async function resetPwd(params) {
  return request(`${process.env.apiTest}/system/user/resetPwd`, {
    method: 'PUT',
    body: params
  });
}
// 导入订单
export async function uploadTemplate(params) {
  const formData = new FormData();
  console.log('params.file.file');
  console.log(params.file.file);
  formData.append('file', params.file.file);
  return request(`${process.env.apiTest}/order/import`, {
    method: 'POST',
    body: formData
  });
}
// 导入产品
export async function importData(params, selfOptions) {
  const formData = new FormData();
  formData.append('file', params.file.file);
  formData.append('updateSupport', true);
  return request(
    `${process.env.apiTest}/system/product/importData`,
    {
      method: 'POST',
      body: formData
    },
    selfOptions
  );
}
// 导出产品
export async function exportData() {
  return request(`${process.env.apiTest}/system/product/export`, {
    method: 'GET',
    headers: {
      download: true
    }
  });
}
// 审核退货订单
export async function updateOrders(params) {
  return request(`${process.env.apiTest}/business/returnOrder`, {
    method: 'PUT',
    body: params
  });
}
// 审核退货订单
export async function fetchOrderList(params) {
  return request(`${process.env.apiTest}/business/returnOrder?${qs.stringify(params)}`, {
    method: 'GET'
  });
}

export async function fetchAllOrderList(params) {
  return request(`${process.env.apiTest}/order?${qs.stringify(params)}`, {
    method: 'GET'
  });
}
// 获取退货订单详情/order/requestReturn
export async function fetchOrderDetail(params) {
  return request(`${process.env.apiTest}/order/requestRet?${qs.stringify(params)}`, {
    method: 'GET'
  });
}
// 更凶退货订单信息
export async function updateOrderList(params) {
  return request(`${process.env.apiTest}/order/requestReturn`, {
    method: 'PUT',
    body: params
  });
}

// 退货规则(新增退货规则)
export async function addRules(params) {
  return request(`${process.env.apiTest}/merchant/returnRules/add`, {
    method: 'POST',
    body: params
  });
}
// 修改退货规则
export async function updateRules(params) {
  return request(`${process.env.apiTest}/merchant/returnRules/update`, {
    method: 'POST',
    body: params
  });
}
// 删除退货规则
export async function deleteRules(params) {
  return request(`${process.env.apiTest}/merchant/returnRules/deleteRulesById?${qs.stringify(params)}`, {
    method: 'POST',
    body: params
  });
}
// 规则详情
export async function fetchRules(params) {
  return request(`${process.env.apiTest}/merchant/returnRules/${params.id}`, {
    method: 'GET'
  });
}
// 规则列表
export async function fetchRulesList(params) {
  return request(`${process.env.apiTest}/merchant/returnRules/getRulesByShopId?${qs.stringify(params)}`, {
    method: 'GET'
  });
}
// 获取州
export async function getAllStateList() {
  return request(`${process.env.apiTest}/system/state/getAllStateList`, {
    method: 'GET'
  });
}
//添加服务信息
export async function addProviderInfo(params) {
  return request(`${process.env.apiTest}/insertServiceProvider?${qs.stringify(params)}`, {
    method: 'GET'
  });
}
//删除服务
export async function deleteProviderInfo(params) {
  return request(`${process.env.apiTest}/deleteServiceProviderById?${qs.stringify(params)}`, {
    method: 'DELETE'
  });
}
// 查询服务信息
export async function roviderByIdInfo(params) {
  return request(`${process.env.apiTest}/findServiceProviderById?${qs.stringify(params)}`, {
    method: 'GET'
  });
}
// 获取服务信息列表
export async function getAllServiceProvider() {
  return request(`${process.env.apiTest}/getAllServiceProvider`, {
    method: 'GET'
    // body: params
  });
}
// 角色管理Role
export async function queryRole(params) {
  return request(`${process.env.apiTest}/system/user/list?${qs.stringify(params)}`, {
    method: 'GET'
  });
}
export async function addRole(params) {
  return request(`${process.env.apiTest}/system/user`, {
    method: 'POST',
    body: params
  });
}
export async function updateRole(params) {
  return request(`${process.env.apiTest}/system/user`, {
    method: 'PUT',
    body: params
  });
}
export async function deleteRole(params) {
  return request(`${process.env.apiTest}/system/user/${params.id}`, {
    method: 'DELETE'
    // body:params
  });
}
export async function changeRoleStatus(params) {
  return request(`${process.env.apiTest}/system/user/changeStatus`, {
    method: 'PUT',
    body: params
  });
}
// GET获取角色选择框列表
export async function getOptionselect(params) {
  return request(`${process.env.apiTest}/system/role/optionselect`, {
    method: 'GET',
    body: params
  });
}

// 获取背景颜色列表
export async function getTheme(params) {
  return request(`${process.env.apiTest}/shopTheme`, {
    method: 'GET',
    body: params
  });
}
// 保存当前使用的主题颜色
export async function saveTheme(params) {
  return request(`${process.env.apiTest}/shopThemeSave`, {
    method: 'POST',
    body: params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  });
}
// 通用上传
export async function commonUpload(params) {
  const formData = new FormData();
  formData.append('file', params.file.file);
  formData.append('updateSupport', true);
  return request(`${process.env.apiTest}/common/upload`, {
    method: 'POST',
    body: formData
  });
}
//用户管理权限
export async function administratorsSa() {
  return request(`${process.env.apiTest}/AdministratorsSa`, {
    method: 'GET'
  });
}
//保存用户管理接口
export async function administratorsSave(params) {
  return request(`${process.env.apiTest}/AdministratorsSave`, {
    method: 'POST',
    body: params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  });
}
// 下载Download attachment
export async function downloadAttachment() {
  return request(`${process.env.downloadApi}/shop_sku.xlsx`, {
    method: 'GET',
    headers: {
      download: true
    }
  });
}

// 退款时间设置
export async function SysRefundTimeSave(params) {
  return request(`${process.env.apiTest}/SysRefundTimeSave`, {
    method: 'POST',
    body: params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  });
}

// 审批时间设置
export async function ApprovaltimeSave(params) {
  return request(`${process.env.apiTest}/ApprovaltimeSave`, {
    method: 'POST',
    body: params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  });
}

// 根据州缩写，查询全部邮编，州通过分号分割;
export async function getZipCodeByStateBatch(params) {
  return request(`${process.env.apiTest}/state/city/getZipCodeByStateBatch?${qs.stringify(params)}`, {
    method: 'GET'
  });
}

// 退货原因
export async function shopStatReturnReason() {
  return request(`${process.env.apiTest}/shopStat/returnReason`, {
    method: 'GET'
  });
}

// 退货区域
export async function shopStatReturnState() {
  return request(`${process.env.apiTest}/shopStat/returnState`, {
    method: 'GET'
  });
}

// 退货订单数据统计
export async function shopStatReturnOrders() {
  return request(`${process.env.apiTest}/shopStat/returnOrders`, {
    method: 'GET'
  });
}

// 退货订单数据统计
export async function shopStatReturnProductAnalysis() {
  return request(`${process.env.apiTest}/shopStat/returnProductAnalysis`, {
    method: 'GET'
  });
}

export function getUpdateServiceProviderUrl() {
  return `${process.env.apiTest}/updateServiceProvider`;
}

export function findRefundSettingById() {
  return request(`${process.env.apiTest}/system/refundSetting/findRefundSettingById`, {
    method: 'POST'
  });
}

export function saveRefundSetting(params) {
  return request(`${process.env.apiTest}/system/refundSetting/saveRefundSetting`, {
    method: 'POST',
    body: params,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
    }
  });
}

/**
 *
 * @param {*} params returnNo,status
 * @returns
 */
export function makeAppointment(params) {
  return request(`${process.env.apiTest}/order/makeAppointment`, {
    method: 'POST',
    body: params
  });
}
